//
//  PageShyViewController.m
//  开心一刻
//
//  Created by lanou on 16/4/6.
//  Copyright © 2016年 刘洋. All rights reserved.
//

#import "PageShyViewController.h"
#import "FristTuiJianTableViewController.h"
#import "TwoMovieTableViewController.h"
#import "ThreeArtTableViewController.h"
#import "FourDUanziTableViewController.h"
@interface PageShyViewController ()<UIScrollViewDelegate>

@property (nonatomic,strong) UIScrollView *myScrollView;
@property (nonatomic,strong) NSMutableArray * array;
@property (nonatomic,strong) FristTuiJianTableViewController * frist;
@property (nonatomic,strong) TwoMovieTableViewController * two;
@property (nonatomic,strong) ThreeArtTableViewController * three;
@property (nonatomic,strong) FourDUanziTableViewController * four;
@end

@implementation PageShyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBar.translucent = NO;
    self.array = [NSMutableArray array];
    UIButton * button1 = [UIButton buttonWithType:UIButtonTypeSystem];
    button1.frame = CGRectMake((KedWidth - 160) / 5, 1, 40, 30);
    [button1 setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [button1 setTitle:@"推荐" forState:UIControlStateNormal];
 [self.view addSubview:button1];
    button1.tag = 100;
    [_array addObject:button1];
    
    UIButton * button2 = [UIButton buttonWithType:UIButtonTypeSystem];
    button2.frame = CGRectMake((KedWidth - 160) / 5 *2 +40 , 1, 40, 30);
    [button2 setTitle:@"视频" forState:UIControlStateNormal];
    [button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_array addObject:button2];
    button2.tag = 101;
    [self.view addSubview:button2];
    
    UIButton * button3 = [UIButton buttonWithType:UIButtonTypeSystem];
    button3.frame = CGRectMake((KedWidth - 160) / 5 *3 +80, 1, 40, 30);
    [button3 setTitle:@"段子" forState:UIControlStateNormal];
    [_array addObject:button3];
    [button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button3.tag = 102;
    [self.view addSubview:button3];
    
    UIButton * button4 = [UIButton buttonWithType:UIButtonTypeSystem];
    button4.frame = CGRectMake((KedWidth - 160) / 5 * 4 +120, 1, 40, 30);
    [button4 setTitle:@"图片" forState:UIControlStateNormal];
    button4.tag = 103;
    [button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_array addObject:button4];
    [self.view addSubview:button4];
    
    [button1 addTarget:self action:@selector(aaa :) forControlEvents:UIControlEventTouchUpInside];
    [button2 addTarget:self action:@selector(aaa :) forControlEvents:UIControlEventTouchUpInside];
    [button3 addTarget:self action:@selector(aaa :) forControlEvents:UIControlEventTouchUpInside];
    [button4 addTarget:self action:@selector(aaa :) forControlEvents:UIControlEventTouchUpInside];
    _myScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0,  32, KedWidth, KedHeight - 64 - 71)];
    _myScrollView.bounces = NO;
    _myScrollView.pagingEnabled = YES;
    _myScrollView.showsHorizontalScrollIndicator = NO;
    _myScrollView.showsVerticalScrollIndicator = NO;
    _myScrollView.contentSize = CGSizeMake(KedWidth * 4, KedHeight - 64 - 71);
    _myScrollView.delegate = self;
    _myScrollView.contentOffset = CGPointMake(KedWidth * 0, 0);
    [self.view addSubview:_myScrollView];
    [self creatView];

}
#pragma mark --- 创建四个界面 ---
- (void)creatView
{
    _frist = [[FristTuiJianTableViewController alloc]init];
    _two = [[TwoMovieTableViewController alloc]init];
    _three = [[ThreeArtTableViewController alloc]init];
    _four = [[FourDUanziTableViewController alloc]init];
    _frist.tableView.frame = CGRectMake(0, 0, KedWidth, KedHeight - 64 - 72);
    [_myScrollView addSubview:_frist.tableView];
    
    _two.tableView.frame = CGRectMake(KedWidth, 0, KedWidth, KedHeight - 64 -72);
    [_myScrollView addSubview:_two.tableView];
    
    _three.tableView.frame = CGRectMake(KedWidth * 2, 0, KedWidth, KedHeight - 64 - 72);
    [_myScrollView addSubview:_three.tableView];
    _four.tableView.frame = CGRectMake(KedWidth * 3, 0, KedWidth, KedHeight - 64 - 72);
    [_myScrollView addSubview:_four.tableView];

}
#pragma mark --- button点击事件 切换界面 ---
- (void)aaa: (UIButton *)button
{
    for (UIButton * button  in _array)
    {
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    _myScrollView.contentOffset = CGPointMake(KedWidth * (button.tag - 100), 0);
}
#pragma mark --- scrollView滑动触发事件 ---
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    for (UIButton * button in _array)
    {
       [ button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    NSInteger index = scrollView.contentOffset.x / KedWidth;
    UIButton * button = _array[index];
[button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
